package com.guoguo.generic;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.YearMonth;
import java.util.Arrays;
import java.util.Date;

public class DemoTwo<T> {
    enum MonthConvertEnum{
        JANUARY("January","一月"),
        FEBRUARY("February","二月"),
        ;
        private String en;
        private String cn;

        MonthConvertEnum(String en, String cn) {
            this.en = en;
            this.cn = cn;
        }

        public String getEn() {
            return en;
        }

        public String getCn() {
            return cn;
        }

        /**
         *
         * 方法描述 根据类型的名称，返回类型的枚举实例。
         *
         */
        static MonthConvertEnum convert(String monthEn) {
            for (MonthConvertEnum month : MonthConvertEnum.values()) {
                if (month.getEn().toUpperCase().equals(monthEn)) {
                    return month;
                }
            }
            return null;
        }
    }

    private static int calculateExponent(int base, int exponent) throws Exception {
        if(exponent<0){
            throw new IllegalArgumentException("指数不能为负数");
        }
        if(exponent == 1){
            return base;
        }else{
            return base * calculateExponent(base, exponent - 1);
        }
    }

    private static int a(int init){
        return ~~init;
    }

    public static void main(String[] args) throws Exception {

        String str = "2021-02";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date d = sdf.parse(str);
        System.out.println(calculateExponent(2,5));
        System.out.println(2 << 3);


//        YearMonth ym = YearMonth.parse(str);
//        System.out.println("本月日期是："+ ym.getMonthValue() +"月");

//        Integer[] arr1 = {1,2,3,4,5,6};
//        String[] arr2 = {"a","b","c","d","e","f"};
//        new DemoTwo().change(arr1, 0, 5);
//        new DemoTwo().change(arr2, 0, 5);
//        toList("aaa","bbb");
    }

    private static <T> void toList(T... aaa) {
        for (T t : aaa) {
            System.out.println("========"+t);
        }
    }

    private T[] change(T[] t, int i, int i1) {
        T temp = t[i];
        t[i] = t[i1];
        t[i1] = temp;
        System.out.println(Arrays.asList(t));
        return t;
    }
}
